package project.android;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;

import android.os.StrictMode;


public class ServerConnection{

	public static String postData(List<NameValuePair> name,String url) throws Exception {
		
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	    StrictMode.setThreadPolicy(policy);
	    String content=null;
	    
	    	HttpClient httpclient = new DefaultHttpClient();
		    HttpPost httppost = new HttpPost(url);
	        httppost.setEntity(new UrlEncodedFormEntity(name));
	        HttpResponse response = httpclient.execute(httppost);       
	        	
	        HttpEntity entity = response.getEntity();
	      
			if (entity != null){
		        InputStream is = entity.getContent();
		        BufferedReader br = new BufferedReader(new InputStreamReader(is));
		        StringBuilder sb = new StringBuilder();
		        String line = null;
		        while ((line = br.readLine()) != null) 
		            sb.append(line + "\n");
		        br.close();
		        content = sb.toString();
		    }
	   
	    return content;
	    
	}
	
	
}
